#include "splash.hpp"

#include "image.hpp"
#include "game.hpp"
#include "graphics.hpp"

namespace nmc
{
    Splash::Splash()
        : mDone(false),
        mFrameCounter(0)
    {
        mDarkbitsLogo = Game::instance()->getImage("data/darkbitslogo_by_haiko.bmp");
    }

    void Splash::logic()
    {
        mFrameCounter++;
    }

    void Splash::draw(Graphics* graphics)
    {
		graphics->setColor(gcn::Color(0xffffff));
		graphics->fillRectangle(gcn::Rectangle(0, 0, 320, 240));
        
        if (mFrameCounter > 50 && mFrameCounter <= 100)
        {
			float l = ((100 - mFrameCounter) * (100 - mFrameCounter)) / (50.0 * 50.0);
			int w = mDarkbitsLogo->getWidth() * (1 + 20 * l);
			int h = (mDarkbitsLogo->getHeight() * mDarkbitsLogo->getWidth()) / w;

			graphics->pushMatrix();
			graphics->translate(160 - w / 2, 120 - h / 2);
			//graphics->scale(0, 0, w, h);
            graphics->drawImage(mDarkbitsLogo, 0, 0);
			graphics->popMatrix();
        }

		if (mFrameCounter > 100)
        {
			int w = mDarkbitsLogo->getWidth();
			int h = (mDarkbitsLogo->getHeight() * mDarkbitsLogo->getWidth()) / w;
			graphics->pushMatrix();
			//graphics->translate(160 - w / 2, 120 - h / 2);
			//graphics->scale(0, 0, w, h);
            graphics->drawImage(mDarkbitsLogo, 0, 0);
			graphics->popMatrix();
        }
    }

    bool Splash::isDone()
    {
        return mFrameCounter > 200;
    }
}